/**    
 * @Title: SpringMvcConfiger.java  
 * @Package com.bicon.authority.mvc  
 * @Description:
 * @author yanhewei@vv.cc.com    
 * @date 2018年9月15日 上午10:41:46  
 * @version V1.0    
*/
package cn.com.ytst.data.integration.configer;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

/**
 * @ClassName: SpringMvcConfiger
 * @Description:
 * @author yanhewei@vv.cc.com
 * @date 2018年9月15日 上午10:41:46
 * 
 */

@Configuration
public class SpringMvcConfiger implements WebMvcConfigurer {

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {

		if (!registry.hasMappingForPattern("/static/**")) {
			registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		}
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
//		 registry.addInterceptor(authenticationInterceptor())
//         .addPathPatterns("/**");
	}
	

	@Bean
	public FreeMarkerViewResolver freeMarkerViewResolver() {
		FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
		resolver.setViewClass(FreeMarkerView.class);
		resolver.setPrefix("");
		resolver.setSuffix(".ftl");
		resolver.setExposeRequestAttributes(true);
		resolver.setExposeSessionAttributes(true);
		resolver.setExposeSpringMacroHelpers(true);

		// <property name="exposeSessionAttributes" value="true" />
		// <property name="exposeSpringMacroHelpers" value="true" />
		resolver.setContentType("text/html; charset=UTF-8");
		resolver.setRequestContextAttribute("rc");
		return resolver;
	}

	/**
	 * <property name="templateLoaderPath" value="/WEB-INF/page/ " /> <property
	 * name="defaultEncoding" value="UTF-8" /> <property name="freemarkerSettings">
	 * <props> <prop key="template_update_delay">0</prop> <prop
	 * key="locale">zh_CN</prop> <prop key="datetime_format">yyyy-MM-dd
	 * HH:mm:ss</prop> <prop key="date_format">yyyy-MM-dd</prop> <prop
	 * key="number_format">#.##</prop> </props> </property> @Title:
	 * freeMarkerConfigurer @Description: @param @return 设定文件 @return
	 * FreeMarkerConfigurer 返回类型 @throws
	 */
	@Bean
	public FreeMarkerConfigurer freeMarkerConfigurer() {
		FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
		freeMarkerConfigurer.setTemplateLoaderPath("classpath:/templates/");
		freeMarkerConfigurer.setDefaultEncoding("UTF-8");
		Properties variables = new Properties();
		variables.put("template_update_delay", "0");
		variables.put("locale", "zh_CN");
		variables.put("datetime_format", "yyyy-MM-dd HH:mm:ss");
		variables.put("date_format", "yyyy-MM-dd");
		variables.put("number_format", "#.##");
		freeMarkerConfigurer.setFreemarkerSettings(variables);
		return freeMarkerConfigurer;
	}
}
